<script setup>
    import {  ref } from "vue";


    import useOrderStore from "@/stores/order/order.js";
    const props = defineProps(["singleOrder","index"]);
    console.log(props.singleOrder);
    import {useRoute} from "vue-router";

    const route = useRoute();
    const useOrder = useOrderStore();
    
    const { order } = useOrder;
    // let status = 
    // console.log();

    
    let MM = ref();
    let SS = ref();
    console.log("props.singleOrder.deadline:",props.singleOrder.deadline);
    console.log(route.query.from);
    // && route.query.from==="orderConfirm"
    // let timer =null;
    if (props.singleOrder.deadline) {

        console.log(props.singleOrder.timer);
        // 清除多余的间歇函数
        if (props.singleOrder.timer!==null) {
            clearInterval(props.singleOrder.timer);
        }

        let timer = setInterval(()=>{
            let date = new Date();
            let now = date.getTime();

            let leftTime = props.singleOrder.deadline-now;
            // console.log(leftTime);
                                                //分钟 转小时 剩余多少分钟
            MM.value = Math.floor(leftTime/1000/60%60) ;
                                                //秒转分钟  剩余多少秒
            SS.value = Math.floor(leftTime/1000%60);
            // console.log(MM.value);
            // console.log(SS.value);

            if (leftTime<=890000) {
                clearInterval(timer);
                console.log("间歇函数清除功能已执行");

                //再查询一次有没有购买 有购买不删除
                if (props.singleOrder.deadline) {
                order.splice(props.index,1);
                }
            }
        },1000)

        props.singleOrder.timer=timer;
        console.log(timer);
        
    }
    
</script>

<template>
    <div class="card">
        <div class="card_title">
            <div class="name">{{ singleOrder.name }}</div>
            <div class="state" v-if="singleOrder.deadline===false">已下单</div>
            <div class="state" v-else >待支付 {{ MM<10 ? "0" + MM : MM }}:{{ SS<10 ? "0" + SS : SS }}</div>
           
        </div>
        <div class="card_content">
            <div class="img_list" >
                <div class="img" v-for="orderItem in singleOrder.list" :key="orderItem.id">
                    <img :src="`http://www.dell-lee.com/imgs/vue3/${orderItem.imgName}.png`" alt="">
                </div>
                <!-- <div class="img">
                    <img src="http://www.dell-lee.com/imgs/vue3/cherry.png" alt="">
                </div>
                <div class="img">
                    <img src="http://www.dell-lee.com/imgs/vue3/orange.png" alt="">
                </div> -->
            </div>
            <div class="count">
                <!-- <label>{{ minute<10 ? "0"+minute : minute }}:{{ sec<10 ? "0"+sec:sec }}</label> -->

                <div class="price">￥{{ singleOrder.acount }}</div>
                <div class="total_number">共{{singleOrder.alNumber}}件</div>
            </div>
        </div>
    </div>
</template>

<style lang="scss" scoped>
@import "@/style/viriables.scss";
@import "@/style/mixins.scss";

.card {
    margin: .18rem;
    padding: .18rem;
    background-color: $bgColor;
    border-radius: .04rem;

    &_title {
        display: flex;
        justify-content: space-between;
        font-size: .16rem;
        .name {
            color: $content-fontcolor;
        }
        .state {
            color: $light-fontColor;
        }
    }

    &_content {
        display: flex;
        margin-top: .18rem;
        .img_list {
            flex: 1;
            display: flex;
            .img {
                margin-right: .08rem;
                img {
                    width: .4rem;
                    height: .4rem;
                    display: block;
                }
            }
        }
        .count {
            width: .6rem;
            text-align: right;
            .price {
                line-height: .2rem;
                color: $hightlight-fontColor;
            }
            .total_number {
                line-height: .14rem;
                margin-top: .06rem;
                font-size: .12rem;
            }
        }
    }
}
</style>